package com.frejoys.app.controller;

import com.frejoys.common.aop.Authority;
import com.frejoys.common.aop.Authorization;
import com.frejoys.common.constant.CommonConstant;
import com.frejoys.common.dto.app.GoodsFiltrationListDto;
import com.frejoys.common.dto.app.GoodsIdDto;
import com.frejoys.common.dto.app.GoodsNameDto;
import com.frejoys.common.dto.app.StoreIdDto;
import com.frejoys.common.response.Result;
import com.frejoys.common.vo.app.GoodsSimpleVo;
import com.frejoys.common.vo.app.GoodsVo;
import com.frejoys.service.GoodsService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@Tag(name = "商品", description = "商品")
@RestController
@RequiredArgsConstructor
@RequestMapping(CommonConstant.routePrefixApp)
@Authorization(Authority.Private)
public class GoodsController {

    private final GoodsService goodsService;

    @Authorization(Authority.Protected)
    @PostMapping("/goods/goodsFiltrationList")
    @Operation(summary = "首页商品列表 排序")
    public Result<List<GoodsVo>> goodsFiltrationList(@RequestBody @Validated GoodsFiltrationListDto dto){
        return Result.success(goodsService.goodsFiltrationList(dto));
    }


    @Authorization(Authority.Protected)
    @PostMapping("/goods/detail")
    @Operation(summary = "商品详情")
    public Result<GoodsVo> goodsDetails(@RequestBody @Validated GoodsIdDto goodsIdDto){
        return Result.success(goodsService.GoodsDetails(goodsIdDto.getId()));
    }


    //猜你喜欢接口 也可以根据商品类型查询相关的商品
    @Authorization(Authority.Protected)
    @PostMapping("/goods/sonGoodsFiltrationList")
    @Operation(summary = "根据品类细类筛选商品列表 排序")
    public Result<List<GoodsVo>> sonGoodsFiltrationList(@RequestBody @Validated GoodsFiltrationListDto dto){
        return Result.success(goodsService.sonGoodsFiltrationList(dto));
    }

    @Authorization(Authority.Protected)
    @PostMapping("/goods/storeGoodsList")
    @Operation(summary = "店铺下的商品")
    public Result<List<GoodsVo>> storeGoodsList(@RequestBody @Validated StoreIdDto dto){
        return Result.success(goodsService.userGoodsList(dto));
    }

    @Authorization(Authority.Protected)
    @PostMapping("/goods/selectGoodsList")
    @Operation(summary = "搜索商品")
    public Result<List<GoodsVo>> selectGoodsList(@RequestBody @Validated GoodsNameDto dto){
        return Result.success(goodsService.selectGoodsList(dto));
    }

    @Authorization(Authority.Protected)
    @PostMapping("/goods/storeGoodsAndCategoryList")
    @Operation(summary = "店铺下的商品 右边商品")
    public Result<List<GoodsSimpleVo>> storeGoodsAndCategoryList(@RequestBody @Validated StoreIdDto dto){
        return Result.success(goodsService.storeGoodsAndCategoryList(dto));
    }

//
//    /**
//     * 商家端-新增店铺商品
//     */
//    @PostMapping("/goods/saveGoods")
//    @Operation(summary = "新增店铺商品")
//    public Result saveGoods(@RequestBody @Validated GoodsSaveDto goodsSaveDto){
//        goodsService.saveGoods(goodsSaveDto);
//        return Result.success();
//    }
//    /**
//     * 商家端-申请商品上架
//     */
//    @PostMapping("/goods/goodsUp")
//    @Operation(summary = "申请商品上架")
//    public Result goodsUp(@RequestBody @Validated IdDto dto){
//        goodsService.goodsUp(dto);
//        return Result.success();
//    }
//
//    /**
//     * 商家端-商品下架
//     */
//    @PostMapping("/goods/goodsDown")
//    @Operation(summary = "申请商品上架")
//    public Result goodsDown(@RequestBody @Validated IdDto dto){
//        goodsService.goodsDown(dto);
//        return Result.success();
//    }
}
